<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xh<!-tml1-transitional.dtd">
<%@page import="bridge.*"%>
<%@page import="java.net.URLEncoder"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Sensor</title>
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
</head>
<body>
<div id="header">
	<div id="logo">
		<h1>Bridge Viz</h1>
	</div>
	<!-- end #logo -->
	<div id="menu">
		<ul>
			<li><a href="project.jsp">The Project</a></li>
			<li><a href="sensors.jsp">Sensor Info</a></li>
			<li><a href="visualization.jsp">Data Visualization</a></li>
			<li><a href="records.jsp">Records</a></li>
			<li><a href="about.jsp">About Us</a></li>
			<li class="active"><a href="#">Administration</a></li>
		</ul>
	</div>
	<!-- end #menu -->
</div>
<!-- end #header -->
<div id="page">
	<div id="content">
		<div class="post">
			<h2 class="title">Add New Sensor</h2>
			<div class="entry">
				<%
					String new_id = request.getParameter("newid");
					String name = request.getParameter("name");
					String type = request.getParameter("type");
					String description = request.getParameter("description");
					DatabaseAccessor db = null;
					Sensor[] sensors = null;
					String[] types = null;
					db = DatabaseAccessor.getInstance();
					if(new_id != null && name != null && type != null && description != null)
					{
						sensors = db.getSensors();
						byte id = Byte.parseByte(new_id);
						for(int k = 0; k < sensors.length; k++)
						{
							if(sensors[k].sensorID == id)
							{
								out.println("<p>Cannot add sensor; sensor id " + new_id + " already in use.</p>");
								break;
							}
							else if(k == sensors.length - 1)
							{
								out.println("<!--" + db.addSensor(new_id, name, type, description) + "-->");
								out.println("<p>Successfully added sensor " + new_id + ".</p>");
								new_id = "";
								name = "";
								type = "";
								description = "";
							}
						}
					}
					else
					{
						new_id = "";
						name = "";
						type = "";
						description = "";
					}
					
					
					types = db.getTypes();
				%>
				<table>
					<tr><td>Sensor ID</td><td>Sensor Name</td><td>Sensor Type</td></tr>
					<form action="addsensors.jsp" method="get"><tr><td><input maxlength='3' size='3' type='text' name='newid' value=''></td><td><input maxlength='32' size='32' type='text' name='name' value='<%=name%>'></td><td><select name="type"><%for(int j = 0; j <types.length; j++){out.print("<option value = '" + types[j] + "' "); if(types[j].equals(type)){out.println(" SELECTED");}out.println(">" + types[j] + "</option>");}%></select></td><td align='right'><input type="submit" value ="Add"></td></tr>
					<tr><td colspan=4>Description</td></tr>
					<tr><td colspan=4><textarea name='description' cols=50 rows=3><%=description%></textarea></td></tr>
					</form>
				</table>
			</div>
		</div>
	</div>
	<!-- end #content -->
	<div id="sidebar">
		<div id="sidebar-content">
			<ul>
				<li>
					<h2>Sensors</h2>
					<ul>
						<li><a href="modifysensors.jsp">View/Modify Sensors</a></li>
						<li><a href="addsensors.jsp">Add Sensor</a></li>
					</ul>
				</li>
				<li>
					<h2>Sensor Types</h2>
					<ul>
						<li><a href="modifysensortypes.jsp">View/Modify Sensor Types</a></li>
						<li><a href="addsensortypes.jsp">Add Sensor Type</a></li>
					</ul>
				</li>
				<li>
					<h2>Database</h2>
					<ul>
						<li><a href="builddb.jsp">Build Database</a></li>
					</ul>
				</li>
			</ul>
		</div>
	</div>
<!-- end #page -->
<div id="footer">
	<p>&copy; 2008. All Rights Reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
<!-- end #footer -->
</body>
</html>
